<script>
	var Interface = function( name, methods ) {
		if ( arguments.length < 2 ) {
			throw new Error( "Interface constructor called with " + arguments.length + " arguments, but expected exactly 2." );
		}
		this.name = name;
		this.methods = [];
		for ( var i = 0, len = methods.length; i < len; i++ ) {
			if ( typeof methods[ i ] != 'string' ) {
				throw new Error( "Interface constructor expects method names to be passed in as a string." );
			}
			this.methods.push( methods[ i ] );
		}
	};

	Interface.ensureImplements = function( object ) {
		if ( arguments.length < 2 ) {
			throw new Error("Function Interface.ensureImplements called with " + arguments.length + " arguments,but expected at least 2.");
		}
		for ( var i = 1, len = arguments.length; i < len; i++ ) {
			var inter_face = arguments[ i ];
			if ( inter_face.constructor !== Interface ) {
				throw new Error( "Function Interface.ensureImplementsexpects arguments two and above to be instances of Interface." );
			}
			for ( var j = 0, methodsLen = inter_face.methods.length; j < methodsLen; j++ ) {
				var method = inter_face.methods[ j ];
				if ( !object[ method ] || typeof object[ method ] !== 'function' ) {
					throw new Error( "Function Interface.ensureImplements: object " + " does not implements the " + inter_face.name + " interface.Method " + method + " was not found." );
				}
			}
		}
	};

	var myInterface = new Interface( "myInterface", [ "add", "remove", "delete" ] );

	var myObject = function( name ) {
		this.name = name;
	};
	myObject.prototype = {
		add: function() {
			alert( "add method" );
		},
		remove: function() {
			alert( "remove method" );
		},
		deletes: function() {
			console.log( this.name );
		}
	};

	var interfaceTest = new myObject( "zhangchen" );
	Interface.ensureImplements( interfaceTest, myInterface );
	interfaceTest.deletes();
</script>